/**
 * 2018年12月26日下午3:22:27
 * @author 谢进财
 */
package com.baihang.project.ds.common;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.baihang.framework.entity.kit.HttpClientResult;
import com.baihang.framework.kit.HttpKit;
import com.baihang.framework.kit.PropKit;

/**
 * 远程调用工具
 *
 */
public class RemoteInvocationKit {
	private static Logger logger = LoggerFactory.getLogger(RemoteInvocationKit.class);
	public static void changeSystemConfig(String myKey,String myValue) throws Exception {
		logger.info("开始调用");
		String url=String.format("%s/%s", PropKit.get("wxUrl"),"webSocket/changeSystemConfig");
		//String url=String.format("%s/%s", "http://localhost:8080","webSocket/changeSystemConfig");
		System.err.println(url);
		Map<String,String> params = new HashMap<String,String>();
		params.put("key", myKey);
		params.put("value", myValue);
		HttpClientResult result = HttpKit.doPost(url, params);
		logger.info(result.getContent());
	}
	//20190115 注释 通过redis操作配置
	/*public static void changeSystemConfigs(String json) {
		logger.info("开始调用修改全部配置");
		String url=String.format("%s/%s", PropKit.get("wxUrl"),"webSocket/changeSystemConfigs");
		//String url=String.format("%s/%s", "http://localhost:8080","webSocket/changeSystemConfig");
		Map<String,String> params = new HashMap<String,String>();
		params.put("json", json);
		HttpClientResult result;
		try {
			result = HttpKit.doPost(url, params);
			logger.info(result.getContent());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			logger.info(e.getMessage());
			e.printStackTrace();
		}
	}*/
	public static void houseStateControl(String state) throws Exception {
		logger.info("开始调用");
		String url=String.format("%s/%s", PropKit.get("wxUrl"),"webSocket/houseStateControl");
		Map<String,String> params = new HashMap<String,String>();
		if("4".equals(state)) {
			url =String.format("%s/%s", PropKit.get("wxUrl"),"webSocket/changeSystemConfig");
			params.put("key", "State");
			params.put("value", state);
		}else {
			params.put("msg", state);			
		}
		System.err.println(url);
		HttpClientResult result = HttpKit.doPost(url, params);
		logger.info(result.getContent());
	}
	/**
	 * 后台根据手机号踢用户
	 * @param tel
	 */
	public static boolean userGetOut(String tel) {
		String url=String.format("%s/%s", PropKit.get("wxUrl"),"webSocket/userGetOut");
		logger.info("开始踢手机号为{}的用户,远程地址为{}",tel,url);
		Map<String,String> params = new HashMap<String,String>();		
		params.put("tel", tel);					
		HttpClientResult result;
		try {
			result = HttpKit.doPost(url, params);
			logger.info(result.getContent());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.info(e.getMessage());
		}
		return true;
	}
	public static boolean resetClien() {
		String url=String.format("%s/%s", PropKit.get("wxUrl"),"webSocket/resetClien");
		logger.info("重置客户端");
					
		HttpClientResult result;
		try {
			result = HttpKit.doPost(url);
			logger.info(result.getContent());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.info(e.getMessage());
		}
		return true;
	}
	public static void main(String[] args) throws Exception {
		RemoteInvocationKit.changeSystemConfig("IsShowLDGD", "1");
	}
}
